home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / PBGetInfo INIT / INIT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-23  |  3.5 KB  |  194 lines  |  [TEXT/KAHL]

  1. #include <Traps.h>
  2. #include <SetUpA4.h>
  3.  
  4. #include "PBGetInfo.h"
  5.  
  6.  
  7.  
  8. int strcmp(char *s1, char *s2)
  9. {
  10.     while(*s1 == *s2 && *s2 && *s1)
  11.     {
  12.         s1++; 
  13.         s2++;
  14.     }
  15.     
  16.     if (*s1 == *s2) 
  17.         return(EQSTR);
  18.     else
  19.         return(!EQSTR);
  20. }
  21.  
  22.  
  23. char *strcpy(char *s1,char *s2)
  24. {
  25.     do
  26.         *s1 = *s2++;
  27.         
  28.     while (*s1++);
  29. }
  30.  
  31.  
  32. void ShowInit(int ID)
  33. {
  34. Handle        procH;
  35.         
  36.     if ((procH = GetResource('PROC', procID)) != 0L)
  37.     {
  38.         HLock(procH);
  39.         CallPascal(ID, -1, *procH);
  40.         HUnlock(procH);
  41.         ReleaseResource(procH);
  42.     }
  43. }
  44.  
  45.  
  46.  
  47. main()
  48. {
  49. char         *moof,installed;
  50. Handle         myCodeRes;
  51. Handle        lockStatusHandle;
  52. long        theSize;
  53. SysEnvRec    theWorld;
  54. CInfoPBRec    myPBRec;
  55. char        volName[256];
  56. char        tempString[256];
  57. int            errCode;
  58. int            vRefNum;
  59. long        freeBytes;
  60.  
  61.  
  62.     RememberA0();
  63.     SetUpA4();
  64.     
  65.     installed = FALSE;
  66.     
  67.     /* get teh startup volume */
  68.     
  69.     errCode = GetVInfo(0,volName,&vRefNum,&freeBytes);
  70.     
  71.     if (errCode != noErr)
  72.         SysBeep(1);
  73.     
  74.     else
  75.     {
  76.         /* get the system folder from the SysEnvirons theWorld.sysVRefNum */
  77.         
  78.         errCode = SysEnvirons(1,&theWorld);
  79.         
  80.         if (errCode != noErr)
  81.         {
  82.             SysBeep(1);
  83.             SysBeep(1);
  84.         }
  85.         
  86.         else
  87.         {
  88.             volName[0] = 0;
  89.             
  90.             myPBRec.dirInfo.ioCompletion = 0L;
  91.             myPBRec.dirInfo.ioNamePtr = (StringPtr) volName;
  92.             myPBRec.dirInfo.ioVRefNum = theWorld.sysVRefNum;
  93.             myPBRec.dirInfo.ioFDirIndex = -1;
  94.             myPBRec.dirInfo.ioDrDirID = 0L;
  95.             
  96.             /* get the dirID and parent dirID of the system folder */
  97.             
  98.             errCode = PBGetCatInfo(&myPBRec,FALSE);
  99.             
  100.             if (errCode != noErr)
  101.             {
  102.                 SysBeep(1);
  103.                 SysBeep(1);
  104.                 SysBeep(1);
  105.             }
  106.             
  107.             else
  108.             {
  109.                 /* load the actual patch which is stored in a resource of type 'RoyW' */
  110.                 
  111.                 myCodeRes = GetNamedResource('RoyW',patchName);
  112.             
  113.                 if(myCodeRes == nil)
  114.                 {
  115.                     SysBeep(1);
  116.                     SysBeep(1);
  117.                     SysBeep(1);
  118.                     SysBeep(1);
  119.                 }
  120.                 
  121.                 else
  122.                 {
  123.                     /* search for the characters 'Moof' in the trap patch code, since this marks the start of the memory reserved for storing pseudo-globals */
  124.                     
  125.                     theSize = GetHandleSize(myCodeRes);
  126.                     for(moof=*myCodeRes;theSize>0 && strcmp(moof,"Moof")!=EQSTR;moof++,theSize--);
  127.                     
  128.                     if (theSize <= 0L || strcmp(moof,"Moof")!=EQSTR)
  129.                     {
  130.                         SysBeep(1);
  131.                         SysBeep(1);
  132.                         SysBeep(1);
  133.                         SysBeep(1);
  134.                         SysBeep(1);
  135.                     }
  136.                     
  137.                     else
  138.                     {
  139.                         /* store the pseudo-globals */
  140.                         
  141.                         moof += 4L;
  142.                         *((long *) moof) = NGetTrapAddress((int) (_HFSDispatch - 0xA000),OSTrap);
  143.                         moof += 4L;
  144.                         *((int *) moof) = theWorld.sysVRefNum;
  145.                         moof += 2L;
  146.                         *((int *) moof) = vRefNum;
  147.                         moof += 2L;
  148.                         *((long *) moof) = myPBRec.dirInfo.ioDrDirID;
  149.                         moof += 4L;
  150.                         *((long *) moof) = myPBRec.dirInfo.ioDrParID;
  151.                         
  152.                         DetachResource(myCodeRes);
  153.                         HUnlock(myCodeRes);
  154.                         MoveHHi(myCodeRes);
  155.                         HLock(myCodeRes);
  156.                         
  157.                         NSetTrapAddress((long) StripAddress(*myCodeRes),(_HFSDispatch - 0xA000),OSTrap);
  158.                         
  159.                         /* lock the system folder! */
  160.                         
  161.                         strcpy(tempString,LOCKMESSAGE);
  162.                         
  163.                         myPBRec.dirInfo.ioCompletion = 0L;
  164.                         myPBRec.dirInfo.ioNamePtr = (StringPtr) tempString;
  165.                         myPBRec.dirInfo.ioVRefNum = 0;
  166.                         myPBRec.dirInfo.ioFDirIndex = 0;
  167.                         myPBRec.dirInfo.ioDrDirID = 0L;
  168.                         
  169.                         lockStatusHandle = GetNamedResource('RoyW',lockStatus);
  170.                 
  171.                         if (lockStatusHandle)
  172.                             strcpy(tempString,(char *) *lockStatusHandle);
  173.                         
  174.                         errCode = PBGetCatInfo(&myPBRec,FALSE);
  175.                         
  176.                         if (errCode == noErr)
  177.                             installed = TRUE;
  178.                     }
  179.                 }
  180.             }
  181.         }
  182.     }
  183.     
  184.     
  185.     if (!installed)
  186.     {
  187.         ShowInit(badICON);
  188.     }
  189.     
  190.     else
  191.         ShowInit(goodICON);
  192.     
  193.     RestoreA4();
  194. }